package com.yyfax.pay.third.model.to.fuiou;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.StaxWriter;
import com.yyfax.framework.model.Content;

import java.io.StringWriter;

/**
 *
 * 独立鉴权-直连，富有返回参数
 * @author xulqb
 * @date 2017-12-21 20:00:14
 * @since v1.0.0
 */
@SuppressWarnings("serial")
@XStreamAlias("FM")
public class WithoutVerifyFuiouContent extends Content {

	/**
	 * 版本号
	 */
	@XStreamAlias("Ver")
	private String version = "";

	/**
	 * 银行卡号
	 */
	@XStreamAlias("CardNo")
	private String cardNo = "";

	/**
	 * 响应代码
	 */
	@XStreamAlias("Rcd")
	private String rcd = "";

	/**
	 * 响应中文描述
	 */
	@XStreamAlias("RDesc")
	private String rDesc = "";

	/**
	 * 商户代码
	 */
	@XStreamAlias("MchntCd")
	private String mchntCd = "";

	private String merchentId;

	/**
	 * 商户流水号
	 */
	@XStreamAlias("OSsn")
	private String oSsn = "";

	/**
	 * 银行名称
	 */
	@XStreamAlias("Cnm")
	private String cnm = "";

	/**
	 * 银行机构号
	 */
	@XStreamAlias("InsCd")
	private String insCd = "";

	/**
	 * 摘要数据
	 */
	@XStreamAlias("Sign")
	private String sign = "";

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getRcd() {
		return rcd;
	}

	public void setRcd(String rcd) {
		this.rcd = rcd;
	}

	public String getrDesc() {
		return rDesc;
	}

	public void setrDesc(String rDesc) {
		this.rDesc = rDesc;
	}

	public String getMchntCd() {
		return mchntCd;
	}

	public void setMchntCd(String mchntCd) {
		this.mchntCd = mchntCd;
	}

	public String getoSsn() {
		return oSsn;
	}

	public void setoSsn(String oSsn) {
		this.oSsn = oSsn;
	}

	public String getCnm() {
		return cnm;
	}

	public void setCnm(String cnm) {
		this.cnm = cnm;
	}

	public String getInsCd() {
		return insCd;
	}

	public void setInsCd(String insCd) {
		this.insCd = insCd;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getMerchentId() {
		return merchentId;
	}

	public void setMerchentId(String merchentId) {
		this.merchentId = merchentId;
	}

	/**
	 * 该实体转换成XML字符串
	 * 
	 * @author xulqb
	 * @date 2017-12-21 15:00:14
	 * @since v1.0.0
	 * @return 返回XML字符串
	 * @throws Exception
	 */
	public String toXml() {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("FM", WithoutVerifyFuiouContent.class);

		try {
			StringWriter strWriter = new StringWriter();
			StaxWriter sw = new StaxWriter(staxDriver.getQnameMap(), staxDriver.getOutputFactory().createXMLStreamWriter(strWriter), false, true);
			xstream.marshal(this, sw);
			sw.close();
			return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + strWriter.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * XML字符串转换成实体{@link WithoutVerifyFuiouContent}
	 * 
	 * @author xulqb
	 * @date 2017-12-21 15:00:14
	 * @since v1.0.0
	 * @param xml
	 * @return 返回{@link PlaceOrderFuiouContent}
	 */
	public static WithoutVerifyFuiouContent fromXml(String xml) {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("FM", WithoutVerifyFuiouContent.class);
		return (WithoutVerifyFuiouContent) xstream.fromXML(xml);
	}

	public static void main(String[] args) throws Exception {
		System.out.println(new WithoutVerifyFuiouContent().toXml());
	}
}
